<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>4. Tutorial</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="../../../index.html" title="ODTONE 0.3">
<link rel="up" href="../index_mih.html" title="ODTONE MIH">
<link rel="prev" href="mih_data_types.html" title="3. Data Types">
<link rel="next" href="../index_sap.html" title="ODTONE SAP">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="'ODTONE - Open Dot Twenty One'" width="100" height="100" src="../../.././images/logo.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mih_data_types.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index_mih.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../index_sap.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" title="4. Tutorial">
<div class="titlepage"><div><div><h4 class="title">
<a name="odtone.library.index_mih.mih_tutorial"></a><a class="link" href="mih_tutorial.html" title="4. Tutorial"> 4. Tutorial</a>
</h4></div></div></div>
<p>
          The tutorial programs in this section show how to use ODTONE MIH.
        </p>
<p>
          <span class="bold"><strong>Generate and send MIH Messages</strong></span>
        </p>
<p>
          To generate and send a MIH message: 
</p>
<pre class="programlisting"><span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">message</span> <span class="identifier">msg</span><span class="special">;</span>
<span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">link_tuple_id</span> <span class="identifier">li</span><span class="special">;</span>
<span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">event_list</span> <span class="identifier">evts</span><span class="special">;</span>

<span class="comment">//...
</span>
<span class="identifier">msg</span> <span class="special">&lt;&lt;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">request</span><span class="special">(</span><span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">request</span><span class="special">::</span><span class="identifier">event_subscribe</span><span class="special">)</span>
    <span class="special">&amp;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">tlv_link_identifier</span><span class="special">(</span><span class="identifier">li</span><span class="special">)</span>
    <span class="special">&amp;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">tlv_event_list</span><span class="special">(</span><span class="identifier">evts</span><span class="special">);</span>

<span class="identifier">io_service</span><span class="special">.</span><span class="identifier">async_send</span><span class="special">(</span><span class="identifier">msg</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">event_subscribe_response_handler</span><span class="special">);</span>
</pre>
<p>
        </p>
<p>
          Notice that we start with the message and then we use the operator &lt;&lt;
          to begin the generation of the message, followed by on of the <a class="link" href="odtone_mih_message_helper_class.html" title="2.2. odtone::mih::message_helper Class Reference">odtone::mih::message_helper</a>
          classes (<a class="link" href="odtone_mih_request_class.html" title="2.4. odtone::mih::request Class Reference">odtone::mih::request</a>,
          <a class="link" href="odtone_mih_response_class.html" title="2.5. odtone::mih::response Class Reference">odtone::mih::response</a>,
          <a class="link" href="odtone_mih_indication_class.html" title="2.3. odtone::mih::indication Class Reference">odtone::mih::indication</a>)
          and then we can pass the parameters starting with the operator &amp; followed
          by the <a class="link" href="odtone_mih_tlv_type_class.html" title="2.13. odtone::mih::tlv_type_ Class Reference">odtone::mih::tlv_type_</a>
          classes.
        </p>
<p>
          To receive and parse a MIH message:
        </p>
<p>
          
</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">capability_discovery_response</span><span class="special">(</span><span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">message</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span><span class="special">&amp;</span> <span class="identifier">ec</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">ec</span><span class="special">)</span> <span class="special">{</span>
        <span class="comment">// do something with the error and don't parse the msg or else,
</span>        <span class="comment">// an iarchive_eof_error exception is thrown
</span>
        <span class="keyword">return</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">status</span> <span class="identifier">st</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">net_type_addr_list</span><span class="special">&gt;</span> <span class="identifier">ntal</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">event_list</span><span class="special">&gt;</span> <span class="identifier">evt</span><span class="special">;</span>

    <span class="identifier">msg</span> <span class="special">&gt;&gt;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">response</span><span class="special">()</span>
        <span class="special">&amp;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">tlv_status</span><span class="special">(</span><span class="identifier">st</span><span class="special">)</span>
        <span class="special">&amp;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">tlv_net_type_addr_list</span><span class="special">(</span><span class="identifier">ntal</span><span class="special">)</span>
        <span class="special">&amp;</span> <span class="identifier">odtone</span><span class="special">::</span><span class="identifier">mih</span><span class="special">::</span><span class="identifier">tlv_event_list</span><span class="special">(</span><span class="identifier">evt</span><span class="special">);</span>

   <span class="comment">//...
</span><span class="special">}</span>
</pre>
<p>
        </p>
<p>
          In this case, to begin parsing we use operator &gt;&gt;. Everything else
          is similar to generating a message.
        </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2009 -2011 Universidade Aveiro<br>Copyright &#169; 2009 -2011 Instituto de Telecomunica&#231;&#245;es - P&#243;lo Aveiro<p>
        This software is distributed under a license. The full license agreement
        can be found in the LICENSE in this distribution. This software may not be
        copied, modified, sold or distributed other than expressed in the named license
        agreement. This software is distributed without any warranty.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mih_data_types.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index_mih.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../index_sap.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
